import socket
import os
import struct
import json
abs_path=r'D:\AKW\高级开发\网络编程\tcp.html'
filename=os.path.basename(abs_path)
filesize=os.path.getsize(abs_path)
file={'filename':filename,'filesize':filesize}

str_file=json.dumps(file)
str_dic_len=len(str_file)

b_dic_file=str_file.encode('utf-8')
b_dic_len=struct.pack('i',len(b_dic_file))

sk=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sk.connect(('127.0.0.1',8000))

sk.send(b_dic_len)
sk.send(b_dic_file)

with open(file['filename'],mode='rb') as f:

    while file['filesize'] >0:
        content = f.read(1024)
        sk.send(content)
        file['filesize']-=len(content)
sk.close()



























